<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\index\controller;

/**
 * Description of ApiDemo
 *
 * @author Dongasai
 */
class ApiDemo extends \think\Controller
{

    public function index()
    {
        //读取分组列表
        $user_id    = session("uid");
        $where      = [
            'user_id' => $user_id
        ];
        $group_list = \app\index\service\Group::lists($where, '', 1, 9999);
        $this->assign('group_list', $group_list);
        return $this->fetch();
    }

    public function loadcate()
    {
        $group_id  = input('group_id');
        $cate_id   = input('cate_id', 0, 'int');
        $cate_list = \app\index\service\Cate::getList($group_id, $cate_id);
        $uid       = session('uid');
        $api_list  = \app\index\service\Api::listForPage($uid, $cate_id, '', 1, 9999);
        return ['cate' => $cate_list, 'api' => $api_list['list']];
    }

    public function demo()
    {
        $api_id = input('api_id', 0, 'int');
        if (!$api_id) {
            return $this->error("缺少必要参数!");
        }
        $api_info = \app\index\service\Api::info($api_id);
        $this->assign('api_info', $api_info);
        return $this->fetch();
    }

}
